package com.jiyun.controller;

import com.jiyun.pojo.entity.User;
import com.jiyun.service.UserService;
import com.jiyun.util.OSSUploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;
    //获取所有用户
    @RequestMapping("getAllUser")
    public List<User> getAllUser(@RequestBody User user){
        return userService.getAllUser(user);
    }
    //获取所有跑单员
    @RequestMapping("getAllpt")
    public List<User> getAllpd(@RequestBody User user){
        System.out.println("ssss"+user);
        return userService.getAllpt(user);
    }
    /*
    * 禁止和解禁用户，禁用后，用户不能进行发布信息操作，解禁之后，可以正常发布
    * */
    @RequestMapping("jinzhi")
    public void jinzhi(Integer userid){
        userService.jinzhi(userid);
    }
    @RequestMapping("jiejin")
    public void jiejin(Integer userid){
        userService.jiejin(userid);
    }
    /*
    * 删除用户或者跑单员
    * 删除跑腿员功能，删除数据之后，要求立即将接单员踢出系统
    * */
    @RequestMapping("deleteUserByUserId")
    public void deleteByUserid(Integer userid){
        userService.deleteById(userid);
    }

    @RequestMapping("getUserByUser")
    public User getUserByUser(@RequestBody User user){
        System.out.println(user);
        return userService.getUserByUser(user);
    }


    //查询当前用户信息
    @RequestMapping("findUserByuserid")
    public User findUserByuserid(Integer userid){
        System.out.println("----------------userid="+userid);
        User userByid = userService.findUserByid(userid);
        if (userByid==null){
            return null;
        }
        return userByid;
    }
    //修改密码和手机号
    @RequestMapping("updateUserpasswordAndphone")
    public void updateUserpasswordAndphone(@RequestBody User user){
        System.out.println("000000000000000000000000000user==="+user);
        userService.updateUserpasswordAndphone(user);
    }


    //修改个人信息
    @RequestMapping("updategerenxinxi")
    public String image(MultipartFile file, User user) throws Exception {
        String filename = file.getOriginalFilename();
        System.out.println("================file"+filename);
        String sx = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
        String url = OSSUploadUtil.uploadFile(file.getInputStream(), sx);
        System.out.println(url);
        user.setImage(url);
        userService.updateUserpasswordAndphone(user);
        return "修改个人信息成功，请返回查看";
    }


}
